import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { configParams } from '../storage-config';

@Injectable({
  providedIn: 'root'
})
export class StorageTransferOrderService {

  headers = configParams.headers;

  serviceUrls: any = {
    queryAllocationListUrl: '/allocation/list', // 查询调拨单list
    queryAllocationDetailUrl: '/allocationDetails/list', // 调拨单 - 详情
    detailsNullifyUrl: '/allocationDetails/nullify', // 调拨单详情 - 作废
    saveAllocationUrl: '/allocation/save', // 调拨单 - 新增
    editAllocationUrl: '/allocation/update', // 调拨单 - 编辑
    deleteAllocationUrl: '/allocation/delete', // 调拨单 - 删除
    allocationExamineUrl: '/allocation/audit' // 调拨单 - 审核等
  };

  constructor(public httpClient: HttpClient) { }

  // 查询调拨单list
  getAllocationList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryAllocationListUrl, params, {headers: this.headers}).toPromise();
  }

  // 调拨单 - 删除
  deleteAllocationData(params: any) {
    return this.httpClient.post(this.serviceUrls.deleteAllocationUrl, params, {headers: this.headers}).toPromise();
  }
  
  // 查询调拨单 详情
  getAllocationDetailData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryAllocationDetailUrl, params, {headers: this.headers}).toPromise();
  }

  /**
   * 新增 | 编辑 调拨单
   * @param params 
   * @param type 0：新增 1：编辑
   * @returns 
   */
  updateAllocationData(params: any, type: number = 0) {
    let url = type === 1 ? this.serviceUrls.editAllocationUrl : this.serviceUrls.saveAllocationUrl;
    return this.httpClient.post(url, params, {headers: this.headers}).toPromise();
  }

  // 调拨单详情 - 作废
  detailsNullifyData(params: any) {
    return this.httpClient.post(this.serviceUrls.detailsNullifyUrl, params, {headers: this.headers}).toPromise();
  }

  // 调拨单 - 审核等...
  allocationExamineData(params: any) {
    return this.httpClient.post(this.serviceUrls.allocationExamineUrl, params, {headers: this.headers}).toPromise();
  }
}